package java9;

import java.util.Scanner;

public class Q5_3 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		double[] arr = new double[n];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = Integer.parseInt(in.next());
		}
		while (true) {
			try {
				int begin = Integer.parseInt(in.next());
				int end = Integer.parseInt(in.next());
				System.out.println(ArrayUtils.findMax(arr, begin, end));
			} catch (NumberFormatException ex) {
				break;
			} catch (IllegalArgumentException ex) {
				System.out.println(ex);
			}

		}
		try {
			System.out.println(ArrayUtils.class.getDeclaredMethod("findMax", double[].class, int.class, int.class));
		} catch (Exception e1) {

		}
		in.close();
	}

}

class ArrayUtils {
	public static double findMax(double[] arr, int begin, int end) throws IllegalArgumentException {
		if (begin >= end) {
			throw new IllegalArgumentException("begin:" + begin + " >= " + "end:" + end);
		} else if (begin < 0) {
			throw new IllegalArgumentException("begin:" + begin + " < " + 0);
		} else if (end > arr.length) {
			throw new IllegalArgumentException("end:" + end + " > arr.length");
		} else {
			double Max = arr[begin];
			for (int i = begin; i < end; i++) {
				if (arr[i] > Max) {
					Max = arr[i];
				}
			}
			return Max;
		}

	}
}
